package com.r_z.controller;


import com.r_z.entity.Menu;
import com.r_z.service.MenuService;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 梁俊
 * @version 1.0
 * @date 2023/5/30
 */
@CrossOrigin
@RestController
public class MenuController {
    @Resource
    MenuService menuService;


    @RequestMapping("/loadMenu")
    @CrossOrigin
    public List<Menu> loadMenu(String userName){
        System.out.println("进来了动态加载导航栏的方法");

        //调用查询父功能的方法
        //menuType:mainMenu 是功能类型中的父功能节点
        List<Menu> mainMenuList = menuService.selectMainMenu("mainMenu",userName);
        //循环得到所有的父功能
        for (Menu menu : mainMenuList) {
            //得到父功能的id
            String parentMenuId = menu.getMenuId();
            System.out.println("父功能的id"+parentMenuId);

            //根据父功能的id查询出子功能的集合
            List<Menu> subMenuList = menuService.selectSubMenu(parentMenuId,userName);
            for (Menu menu1 : subMenuList) {
                System.out.println(menu1.getMenuId()+"\t"+menu1.getMenuName());
            }
            //把父功能对应的子功能放到map集合中
            menu.setSubMenuList(subMenuList);

        }
        return mainMenuList;
    }


}
